﻿@model Services.Schedules
@{
    ViewBag.Title = "EditMySchedule";
    Layout = "~/_Layout.cshtml";
}
<style type="text/css">
    .schedule_content {
        width: 400px;
        height: 100px;
    }
</style>
<h2>EditMySchedule</h2>
<div id="div_schedule_info">
    @using (Html.BeginForm("EditSchedule", "Schedule", FormMethod.Post, new { @schedule = Model }))
    {
        @Html.HiddenFor(p => p.Id)
        @Html.HiddenFor(p => p.BeginDate)
        @Html.HiddenFor(p => p.ApproveDate)
        @Html.HiddenFor(p => p.ApproveUid)
        @Html.HiddenFor(p => p.SendUid)
        <input type="hidden" name="tag" value='@ViewData["tag"]' />
        <table class="tab">
            <tr>
                <td colspan="2" style="text-align: center;"><span id="span_title_info" style="font-weight: bold;"></span></td>
            </tr>
            <tr>
                <td>标题:</td>
                <td>@Html.TextBoxFor(p => p.Title)</td>
            </tr>
            <tr>
                <td>内容:</td>
                <td>@Html.TextAreaFor(p => p.Contents, new { @class = "schedule_content" })</td>
            </tr>
            <tr>
                <td>审批人:</td>
                <td>@Html.TextBoxFor(p => p.ApproveUid, new { @readonly = "readonly" })</td>
            </tr>
            <tr>
                <td>审批内容:</td>
                <td>@Html.TextAreaFor(p => p.ApproveContent, new { @class = "schedule_content", @readonly = "readonly" })</td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input id="btn_submit" type="submit" class="btn" value="保存" onclick="return CheckForm();" />

                    <input id="btn_back" type="button" class="btn" value="返回" />

                    <input id="btn_del" type="button" class="btn" value="删除" />
                </td>
            </tr>
        </table>
    }
</div>
<script type="text/javascript">
    var tag = '@Request["tag"]'
    if (tag == "edit") {
        $("#btn_submit").val("保存");
    }
    if (tag == "submit") {
        $("#div_schedule_info input[type=text]").each(function () {
            $(this).attr("readonly", "readonly");
        })
        $("#div_schedule_info textarea").each(function () {
            $(this).attr("readonly", "readonly");
        })
        $("#btn_submit").val("提交");
    }

    $("#btn_back").click(function () {
        window.location.href = "/Schedule/MyScheduleList";
    })

    $("#btn_del").click(function () {
        if (!window.confirm("确定要删除这条计划吗？")) {
            return;
        }
        var url = '@Url.Action("DeleteSchedule", "Schedule")'
        SendAjax("get", url, { ran: Math.random(), schId: '@Model.Id' }, "text", function (data) {
            alert(data);
            window.location.href = '@Url.Action("MyScheduleList", "Schedule")'
        });
    })

    function CheckForm() {
        var v1 = $("#Title").val();
        var v2 = $("#Contents").val();

        if (v1 == "" || v2 == "") {
            return false;
        }
        return true;
    }
</script>
